﻿-- ============================================= 
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[proc_FinanceMonthTable_Create_G] 
	(
		@StartDate NCHAR(10),
		@EndDate NCHAR(10),
		@userid VARCHAR(10),
		@username NVARCHAR(10)
	)
AS
BEGIN
	
---------------------------------------------------------------------------------------------
DECLARE @bd int,@wz int,@qt INT,@qyQQ INT,@qytz INT,@gdzc int,@xfml DECIMAL(18,2),@xsml DECIMAL(18,2),@xse DECIMAL(18,2),@albb DECIMAL(18,2)
DECLARE @mlhj DECIMAL(18,2),@xzys DECIMAL(18,2),@wksr DECIMAL(18,2),@tx DECIMAL(18,2),@rcfy DECIMAL(18,2),@cl DECIMAL(18,2)
DECLARE @sscl DECIMAL(18,2),@zxf DECIMAL(18,2)
---------------------------------------------------------------------------------------------

Declare @indextable Table(id int Identity(1,1),cid int,cname nvarchar(100),nid int,maname nvarchar(50))
Insert Into @indextable(cid,cname,nid,maname)  

--Select companyid ,name ,Pid,
-- (SELECT ma.name FROM	zzjg ma WHERE ma.Id=zzjg.pid AND ma.companyid=0 and ma.[level]=2)
 
--From zzjg WHERE companyid <>6 and [level]=3
--2014.12.3 管理区下设二级管理区，查询管理区ID和名称时分开查找
 Select companyid ,name ,
  Pid,
 isnull((SELECT ma.name FROM	zzjg ma WHERE ma.Id=zzjg.pid AND ma.companyid=0 and (ma.[level]=2 or ma.[level]=3)),'') as a
 
From zzjg WHERE companyid <>6 and companyid <>0 and [level]=3

--Select Id,CompanyName,Mid,(SELECT ma.CompanyName
--                                                                         FROM
--                                                                         	ManagementArea ma WHERE ma.Id=Company.Mid AND ma.flag=0 )
--                                                From Company WHERE id <>6
	Declare @sRq Datetime,@eRq Datetime
	Set @sRq = Convert(Datetime, @StartDate + ' 00:00:00')
	Set @eRq = Convert(Datetime, @EndDate + ' 23:59:59')

--insert into _lsb(nr) select '@indextable表中单位:'+ Convert(varchar,cid)+cname+'；indextable序号：'+Convert(varchar,id) from @indextable  


Declare @start int, @end int, @companyId int ,@companyName nvarchar(50), @today INT,@nid INT,@maname  nvarchar(50)
	Select  @end=Count(Id) From @indextable
	Select  @start=1
	
--insert into _lsb(nr) values( '进入循环之前，@indextable表总记录数:'+ Convert(varchar,@end) )	
	
	While(@start<=@end)
BEGIN
	Select @companyId=cid,@companyName=cname,@nid=nid,@maname=maname
	 From @indextable Where Id=@start
	 
--insert into _lsb(nr) values( '开始进入循环，@indextable表中序号:'+ Convert(varchar,@start)+@companyName )

--ProductId in (1,37) 百度数AND NOE_Flag<>2
SET @bd= 
--ISNULL((SELECT  COUNT(DISTINCT orderid)
--  FROM Project AS p WHERE CONVERT(VARCHAR(10),createdate,120) BETWEEN @StartDate AND @EndDate AND NOE_Flag<>2
--AND companyid=@companyId AND ProductId in (1,37) AND typeid=1  and p.OrderId NOT IN (SELECT oid FROM 
--Order_Change oc WHERE oid IN (SELECT distinct orderid FROM Project p2 WHERE 
--                       p2.CompanyId=@companyId AND  p2.CreateDate<@StartDate and p2.OrderId=p.OrderId )
-- AND CONVERT(VARCHAR(10),oc.shqrq,120) BETWEEN  @StartDate AND @EndDate 


--)  AND p.SalePrice!=0  
 

-- AND Id NOT IN (SELECT  Project_Id 
--                  FROM Order_Change_Project where Order_Change_Project.companyid =@companyId AND Order_Change_Project.Project_Id!=0)
-- AND CHARINDEX('对冲',Convert(varchar(8000),p.[Description]))<=0),0)
 ISNULL((SELECT  COUNT(DISTINCT p.orderid)
  FROM Project AS p,Order_Change oc,[Order] o WHERE p.createdate BETWEEN @sRq AND  @eRq AND p.NOE_Flag<>2
AND p.companyid=@companyId AND ProductId in (1,37) AND p.typeid=1  
--当月成单。所有有效的成单
AND o.OId=p.OrderId AND o.StateId<6 AND o.StateId>=1 AND o.AuditDate BETWEEN @sRq AND  @eRq
 
AND p.SalePrice!=0   

 AND p.Id NOT IN (SELECT  Project_Id FROM Order_Change_Project where Order_Change_Project.companyid =@companyId AND Order_Change_Project.Project_Id!=0)
 
 AND CHARINDEX('对冲',Convert(varchar(8000),p.[Description]))<=0),0)
 
 ----------------------
 DECLARE @bd_a int
 set @bd_a=isnull((SELECT COUNT(DISTINCT o.oid ) FROM [Order] o,Order_Change_Hedge och,Project p
WHERE p.CompanyId=@companyId AND p.TypeId=1 AND o.StateId=6 AND o.AuditDate<@StartDate AND och.OId=o.OId AND o.NOE_Flag<>2
AND och.UpTime BETWEEN @sRq AND  @eRq
AND o.OId = p.OrderId  
and p.ProductId IN (1,37)  ),0) 
 
 ----------------------
 SET @bd=@bd-@bd_a
 
--ProductId in (50,51)网站数AND NOE_Flag<>2 
SET @wz=
--ISNULL(( SELECT 
-- COUNT(DISTINCT orderid)
--  FROM Project AS p WHERE CONVERT(VARCHAR(10),createdate,120) BETWEEN @StartDate AND @EndDate AND NOE_Flag<>2
--AND companyid =@companyId AND ProductId in (50,51) AND typeid=1  and p.OrderId NOT IN (select oid from (SELECT oid FROM 
--Order_Change oc WHERE  oid IN (SELECT distinct orderid FROM Project p2 WHERE p2.CompanyId=@companyId AND  p2.CreateDate<@StartDate  and p2.OrderId=p.OrderId )

-- AND CONVERT(VARCHAR(10),oc.shqrq,120) BETWEEN  @StartDate AND @EndDate

--      ) AS nb2
--)   AND p.SalePrice!=0

-- AND Id NOT IN (SELECT  Project_Id 
--                  FROM Order_Change_Project where Order_Change_Project.companyid =@companyId  AND Order_Change_Project.Project_Id!=0)
-- AND CHARINDEX('对冲',Convert(varchar(8000),p.[Description]))<=0
--),0)
 ISNULL((SELECT  COUNT(DISTINCT p.orderid)
  FROM Project AS p,Order_Change oc,[Order] o WHERE p.companyid=@companyId AND p.typeid=1  AND p.createdate BETWEEN @sRq AND  @eRq AND p.NOE_Flag<>2
AND ProductId in (select id from Product where flag=1 ) 
--当月成单。所有有效的成单
AND o.OId=p.OrderId AND o.StateId<6 AND o.StateId>=1 AND o.AuditDate BETWEEN @sRq AND  @eRq
 
AND p.SalePrice!=0   

 AND p.Id NOT IN (SELECT  Project_Id FROM Order_Change_Project where Order_Change_Project.companyid =@companyId AND Order_Change_Project.Project_Id!=0)
 
 AND CHARINDEX('对冲',Convert(varchar(8000),p.[Description]))<=0),0)


-------------------------
DECLARE @wz_a INT

set @wz_a= isnull((SELECT COUNT(DISTINCT o.oid ) FROM [Order] o,Order_Change_Hedge och,Project p
WHERE p.CompanyId=@companyId AND p.TypeId=1 AND o.StateId=6 AND o.AuditDate<@StartDate AND och.OId=o.OId AND o.NOE_Flag<>2
AND och.UpTime BETWEEN @sRq AND  @eRq
AND o.OId = p.OrderId  
and p.ProductId in (select id from Product where flag=1 )  ),0) 

-------------------------
SET @wz=@wz-@wz_a
  

--ProductId in (68,71,112,116)企业QQ数AND NOE_Flag<>2
SET @qyQQ=
--ISNULL(( SELECT 
-- COUNT(DISTINCT orderid)
--  FROM Project AS p WHERE CONVERT(VARCHAR(10),createdate,120) BETWEEN @StartDate AND @EndDate AND NOE_Flag<>2
--AND companyid =@companyId AND ProductId in (68,71,112,116) AND typeid=1  and p.OrderId NOT IN (SELECT oid FROM 
--Order_Change oc WHERE  oid IN (SELECT distinct orderid FROM Project p2 WHERE p2.CompanyId=@companyId AND  p2.CreateDate<@StartDate  and p2.OrderId=p.OrderId )

-- AND CONVERT(VARCHAR(10),oc.shqrq,120) BETWEEN  @StartDate AND @EndDate

--)   AND p.SalePrice!=0

-- AND Id NOT IN (SELECT  Project_Id 
--                  FROM Order_Change_Project where Order_Change_Project.companyid =@companyId  AND Order_Change_Project.Project_Id!=0)
-- AND CHARINDEX('对冲',Convert(varchar(8000),p.[Description]))<=0
--),0)  
 ISNULL((SELECT  COUNT(DISTINCT p.orderid)
  FROM Project AS p,Order_Change oc,[Order] o WHERE p.companyid=@companyId AND p.createdate BETWEEN @sRq AND  @eRq AND p.NOE_Flag<>2
AND ProductId in (68,71,112,116) AND p.typeid=1  
--当月成单。所有有效的成单
AND o.OId=p.OrderId AND o.StateId<6 AND o.StateId>=1 AND o.AuditDate BETWEEN @sRq AND  @eRq
 
AND p.SalePrice!=0   

 AND p.Id NOT IN (SELECT  Project_Id FROM Order_Change_Project where Order_Change_Project.companyid =@companyId AND Order_Change_Project.Project_Id!=0)
 
 AND CHARINDEX('对冲',Convert(varchar(8000),p.[Description]))<=0),0)
 
-----------------------------
DECLARE @qyQQ_a int
set @qyQQ_a=isnull((SELECT COUNT(DISTINCT o.oid ) FROM [Order] o,Order_Change_Hedge och,Project p
WHERE p.CompanyId=@companyId AND p.TypeId=1 AND o.StateId=6 AND o.AuditDate<@StartDate AND och.OId=o.OId AND o.NOE_Flag<>2
AND och.UpTime BETWEEN @sRq AND  @eRq
AND o.OId = p.OrderId  
and p.ProductId IN (68,71,112,116)  ),0) 

-----------------------------
SET @qyQQ=@qyQQ-@qyQQ_a


--ProductId in (39)通址数AND NOE_Flag<>2
SET @qytz=
--ISNULL(( SELECT 
-- COUNT(DISTINCT orderid)
--  FROM Project AS p WHERE CONVERT(VARCHAR(10),createdate,120) BETWEEN @StartDate AND @EndDate AND NOE_Flag<>2
--AND companyid =@companyId AND ProductId in (39) AND typeid=1  and p.OrderId NOT IN (SELECT oid FROM 
--Order_Change oc WHERE  oid IN (SELECT distinct orderid FROM Project p2 WHERE p2.CompanyId=@companyId AND  p2.CreateDate<@StartDate  and p2.OrderId=p.OrderId )

-- AND CONVERT(VARCHAR(10),oc.shqrq,120) BETWEEN  @StartDate AND @EndDate

--)   AND p.SalePrice!=0

-- AND Id NOT IN (SELECT  Project_Id 
--                  FROM Order_Change_Project where Order_Change_Project.companyid =@companyId  AND Order_Change_Project.Project_Id!=0)
-- AND CHARINDEX('对冲',Convert(varchar(8000),p.[Description]))<=0
--),0)  
 ISNULL((SELECT  COUNT(DISTINCT p.orderid)
  FROM Project AS p,Order_Change oc,[Order] o WHERE p.companyid=@companyId AND ProductId =39 AND p.typeid=1 AND  
  p.createdate BETWEEN @sRq AND  @eRq AND p.NOE_Flag<>2

--当月成单。所有有效的成单
AND o.OId=p.OrderId AND o.StateId<6 AND o.StateId>=1 AND o.AuditDate BETWEEN @sRq AND  @eRq
 
AND p.SalePrice!=0   

 AND p.Id NOT IN (SELECT  Project_Id FROM Order_Change_Project where Order_Change_Project.companyid =@companyId AND Order_Change_Project.Project_Id!=0)
 
 AND CHARINDEX('对冲',Convert(varchar(8000),p.[Description]))<=0),0)

--------------------
DECLARE @qytz_a int
set @qytz_a=isnull((SELECT COUNT(DISTINCT o.oid ) FROM [Order] o,Order_Change_Hedge och,Project p
WHERE p.CompanyId=@companyId AND p.TypeId=1 AND o.StateId=6 AND o.AuditDate<@StartDate AND och.OId=o.OId AND o.NOE_Flag<>2
AND och.UpTime BETWEEN @sRq AND  @eRq
AND o.OId = p.OrderId  
and p.ProductId =39  ),0) 

--------------------
SET @qytz=@qytz-@qytz_a

--ProductId not in (1,37,50,51,68,71,112,116,39) 其他数AND NOE_Flag<>2
SET @qt= 
--ISNULL((SELECT 
-- COUNT(DISTINCT orderid)
--  FROM Project AS p WHERE CONVERT(VARCHAR(10),createdate,120) BETWEEN @StartDate AND @EndDate AND NOE_Flag<>2
--AND companyid =@companyId AND ProductId not in (1,37,50,51,68,71,112,116,39,22,29,33) AND typeid=1 
-- and p.OrderId NOT IN (SELECT oid FROM 
--Order_Change oc WHERE  oid IN (SELECT distinct orderid FROM Project p2 WHERE p2.CompanyId=@companyId AND  p2.CreateDate<@StartDate and p2.OrderId=p.OrderId  )

-- AND CONVERT(VARCHAR(10),oc.shqrq,120) BETWEEN  @StartDate AND @EndDate

--)   AND p.SalePrice!=0

-- AND Id NOT IN (SELECT  Project_Id 
--                  FROM Order_Change_Project where Order_Change_Project.companyid =@companyId  AND Order_Change_Project.Project_Id!=0)
-- AND CHARINDEX('对冲',Convert(varchar(8000),p.[Description]))<=0
-- ),0)
 ISNULL((SELECT  COUNT(DISTINCT p.orderid)
  FROM Project AS p,Order_Change oc,[Order] o WHERE p.companyid=@companyId AND p.createdate BETWEEN @sRq AND  @eRq AND p.NOE_Flag<>2
AND ProductId not in (1,37,50,51,68,71,112,116,39,22,29,33) AND p.typeid=1  
--当月成单。所有有效的成单
AND o.OId=p.OrderId AND o.StateId<6 AND o.StateId>=1 AND o.AuditDate BETWEEN @sRq AND  @eRq
 
AND p.SalePrice!=0   

 AND p.Id NOT IN (SELECT  Project_Id FROM Order_Change_Project where Order_Change_Project.companyid =@companyId AND Order_Change_Project.Project_Id!=0)
 
 AND CHARINDEX('对冲',Convert(varchar(8000),p.[Description]))<=0),0)
 
 -----------------------
 DECLARE @qt_a int
 set @qt_a=isnull((SELECT COUNT(DISTINCT o.oid ) FROM [Order] o,Order_Change_Hedge och,Project p
WHERE p.CompanyId=@companyId AND o.StateId=6 AND p.TypeId=1 AND o.AuditDate<@StartDate AND och.OId=o.OId AND o.NOE_Flag<>2
AND och.UpTime BETWEEN @sRq AND  @eRq
AND o.OId = p.OrderId  
and p.ProductId not in (1,37,50,51,68,71,112,116,39,22,29,33,102,103,104,113,119,128)   ),0) 
 
 -----------------------
SET @qt=@qt-@qt_a
--------------------------
--阿里巴巴
SET @albb=
 ISNULL((SELECT  COUNT(DISTINCT p.orderid)
  FROM Project AS p,Order_Change oc,[Order] o WHERE p.companyid=@companyId AND p.typeid=1 AND p.createdate BETWEEN @sRq AND  @eRq AND p.NOE_Flag<>2
AND ProductId in (102,103,104,113,119,128)  
--当月成单。所有有效的成单
AND o.OId=p.OrderId AND o.StateId<6 AND o.StateId>=1 AND o.AuditDate BETWEEN @sRq AND  @eRq
 
AND p.SalePrice!=0   

 AND p.Id NOT IN (SELECT  Project_Id FROM Order_Change_Project where Order_Change_Project.companyid =@companyId AND Order_Change_Project.Project_Id!=0)
 
 AND CHARINDEX('对冲',Convert(varchar(8000),p.[Description]))<=0),0)
 
-----------------------------
DECLARE @albb_a int
set @albb_a=isnull((SELECT COUNT(DISTINCT o.oid ) FROM [Order] o,Order_Change_Hedge och,Project p
WHERE p.CompanyId=@companyId AND p.TypeId=1 AND o.StateId=6 AND o.AuditDate<@StartDate AND och.OId=o.OId AND o.NOE_Flag<>2
AND och.UpTime BETWEEN @sRq AND  @eRq
AND o.OId = p.OrderId  
and p.ProductId IN (102,103,104,113,119,128)  ),0) 

-----------------------------
SET @albb=@albb-@albb_a


--------------------------

--续费毛利AND NOE_Flag<>2 and oid IN (SELECT oid FROM [Order] o WHERE companyId=@companyId AND o.NOE_Flag<>2 )
SET @xfml=ISNULL(( SELECT sum(saleprice-costprice) AS 毛利 FROM project WHERE 
companyid =@companyId  AND typeid=2   AND createdate BETWEEN @sRq AND  @eRq  
AND  ProductId not IN (22,29,33) AND NOE_Flag<>2 ),0)+
ISNULL((SELECT sum(dch_xfml) FROM Order_Change_Hedge WHERE CompanyId 
=@companyId and UpTime BETWEEN @sRq AND  @eRq
 and oid IN (SELECT oid FROM [Order] o WHERE companyId=@companyId AND o.NOE_Flag<>2 )
),0)

--销售毛利 AND NOE_Flag<>2 and oid IN (SELECT oid FROM [Order] o WHERE companyId=@companyId AND o.NOE_Flag<>2 )
SET @xsml=ISNULL(( SELECT sum(saleprice-costprice) AS 毛利 FROM project WHERE 
companyid =@companyId AND typeid=1   AND createdate BETWEEN @sRq AND  @eRq  
AND ProductId not IN (22,29,33) AND NOE_Flag<>2),0)+
ISNULL((SELECT sum(dch_xzml) FROM Order_Change_Hedge WHERE CompanyId =@companyId
 and UpTime BETWEEN @sRq AND  @eRq
  and oid IN (SELECT oid FROM [Order] o WHERE companyId=@companyId AND o.NOE_Flag<>2 )
),0)

------------------------------------------------------------------------------------------------------------
--销售额 AND NOE_Flag<>2 and oid IN (SELECT oid FROM [Order] o WHERE companyId=@companyId AND o.NOE_Flag<>2 )
SET @xse=ISNULL(( SELECT SUM (F_YingShou) FROM [Order] WHERE 
 companyid =@companyId   AND  AuditDate BETWEEN @sRq AND  @eRq  AND StateId>=1 
AND NOE_Flag<>2),0)
+
ISNULL((SELECT sum(dch_chd) FROM Order_Change_Hedge WHERE CompanyId =@companyId
 and UpTime  BETWEEN @sRq AND  @eRq
 and oid IN (SELECT oid FROM [Order] o WHERE companyId=@companyId AND o.NOE_Flag<>2 ) )
 ,0)

--毛利合计 (=续费毛利+销售毛利) 
SET @mlhj=@xfml+@xsml 


--新增应收  AND NOE_Flag<>2 and oid IN (SELECT oid FROM [Order] o WHERE companyId=@companyId AND o.NOE_Flag<>2 )
SET @xzys=ISNULL(( Select Sum(YingShouPrice-ShiShouPrice) From [Order] WHERE CompanyId =@companyId
and AuditDate BETWEEN @sRq AND  @eRq  AND StateId>=1   AND NOE_Flag<>2 ),0)+
ISNULL((SELECT sum(dch_ysh) FROM Order_Change_Hedge WHERE CompanyId =@companyId
 and UpTime  BETWEEN @sRq AND  @eRq
  and oid IN (SELECT oid FROM [Order] o WHERE companyId=@companyId AND o.NOE_Flag<>2 )
),0)

--尾款收入and oid IN (SELECT oid FROM [Order] o WHERE companyId=@companyId AND o.NOE_Flag<>2 )
SET @wksr=ISNULL(( Select Sum(Prices) From Order_PaymentRecord,[Order] o 
                   Where Order_PaymentRecord.CompanyId =@companyId and SWId=2 
and FinanceDate BETWEEN @sRq AND  @eRq
 and Order_PaymentRecord.oid =o.OId AND o.NOE_Flag<>2 AND Order_PaymentRecord.FinanceDate<>o.AuditDate
),0)
+
ISNULL((SELECT sum(dch_wk) FROM Order_Change_Hedge WHERE CompanyId =@companyId and 
UpTime  BETWEEN @sRq AND  @eRq 
 and oid IN (SELECT oid FROM [Order] o WHERE companyId=@companyId AND o.NOE_Flag<>2 )
),0)
-----------------------
--当日成单当日收回来的尾款，不参与计算	，算在当日的实收里	 2012-10-10
-----------------------

--摊销
SET @tx=ISNULL((SELECT SUM(cm.ConsumableMoney) FROM ConsumableMonth cm WHERE cm.CompanyIdCur=@companyId and cm.ConsumableDate BETWEEN  @sRq AND  @eRq),0)

--日常费用 费用类和资产类参与计算 ，二级分类里部门基金不参与 SubjectId NOT IN (231,234,236,237,238,239,196,201,207,176)
--员工工资+税费+电话费+宽带费+水电费+邮寄费+办公品印刷费+低值消耗品+交通费+维修维护费+车辆养护费+差旅费+招待费
-- +手续费+常规财务费+其他财务费+招聘费+培训费+广告费+市场礼品+总办费用+上缴管理费+其他支出+低值资产

SET @rcfy=ISNULL(( Select Sum(OutlayPrice) From Finance_Outlay Where CompanyIdCur =@companyId 
and CreateDate BETWEEN @sRq AND  @eRq
  AND SubjectId  IN (211,213,217,218,215,219,220,221,222,223,224,225,226,228,240,241,230,242,232,233,239,207,197,175) AND Finance_Outlay.A_tx!=1),0)

--纯利
SET @cl=(@mlhj-@tx-@rcfy)

--实收纯利 
SET @sscl=(@cl+@wksr-@xzys)

--装修费(231)
SET @zxf=ISNULL(( Select Sum(OutlayPrice) From Finance_Outlay Where CompanyIdCur =@companyId and [SubjectId]=231
and CreateDate BETWEEN @sRq AND  @eRq 
),0)
	
--固定资产支出(176)
SET @gdzc=ISNULL(( Select Sum(OutlayPrice) From Finance_Outlay Where CompanyIdCur =@companyId and [SubjectId] =176
and CreateDate BETWEEN @sRq AND  @eRq
),0)	
	
------------------------------------------------------------------------------------------------	

SELECT @today=COUNT(1) FROM FinanceMonthTable WHERE left(Convert(nchar(10),TMonth,120),7)=left(Convert(nchar(10),@StartDate,120),7) AND companyid=@companyId
IF 	@today>0
BEGIN
	DELETE [FinanceMonthTable] WHERE left(Convert(nchar(10),TMonth,120),7)=left(Convert(nchar(10),@StartDate,120),7) AND companyid=@companyId
END
INSERT INTO [FinanceMonthTable]
           ([MAid]
           ,[MAname]
           ,[bd]
           ,[wz]
           ,[qt]
           ,[xfml]
           ,[xsml]
           ,[xse]
           ,[mlhj]
           ,[xzys]
           ,[wksr]
           ,[tx]
           ,[rcfy]
           ,[cl]
           ,[sscl]
           ,[zxf]
           ,[createdate]
           ,[userid]
           ,[username]
           ,TMonth
           ,qyQQ
           ,tz
           ,CompanyId
           ,CompanyName
           ,gdzc,albb)
     VALUES(
     	   @nid,
     	   @maname
           ,@bd
           ,@wz
           ,@qt
           ,@xfml
           ,@xsml
           ,@xse
           ,@mlhj
           ,@xzys
           ,@wksr
           ,@tx
           ,@rcfy
           ,@cl
           ,@sscl
           ,@zxf
           ,GETDATE()
           ,@userid
           ,@username
           ,@StartDate
           ,@qyQQ
           ,@qytz
           ,@CompanyId
           ,@companyName
           ,@gdzc,@albb
           
	)
		
	Set @start=@start+1--自增
	--insert into _lsb(nr) values( '循环尾，@start自增长:'+ Convert(varchar,@start) )
	END
END
RETURN
